package com.wenlin.myproduction.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.base.BaseSwipeActivity;
import com.wenlin.myproduction.util.ToastUtils;
import com.wenlin.myproduction.util.UI;
import com.wenlin.myproduction.util.ValCommon;
import com.wenlin.myproduction.widget.ShuDuView2;

import butterknife.BindView;
import butterknife.OnClick;

public class ShuDuActivity2 extends BaseSwipeActivity {
    @BindView(R.id.shu_du_view)
    ShuDuView2 sdv;
    @BindView(R.id.et)
    EditText et;
    @BindView(R.id.tv_total)
    TextView tvTotal;

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, ShuDuActivity2.class);
        activity.startActivity(intent);
    }

    @Override
    public int getContentView() {
        return R.layout.activity_shu_du2;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(ValCommon.SHU_DU_VIEW);
        sdv.setEdit(true);
        et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String str = s.toString();
                UI.setText(tvTotal, str.length());
            }
        });
    }

    @OnClick({R.id.tv_set})
    void click(View view) {
        if (view.getId() == R.id.tv_set) {
            String str = UI.getEtText(et);
            if (str.length() == 81) {
                sdv.setPuzzle(str);
            } else {
                ToastUtils.getInstance().showInfo("题目异常");
            }
        }
    }
}
